<!-- 折线图 -->
<style lang="stylus" scoped>
.xingzhenmultiplebar
  height 100px
  background-size 100% 100%
  .main
    width 100%
    height calc(100% - 100px)
    margin-top -15px
</style>


<template>
<div class="xingzhenmultiplebar">
  <p class='titlemultiplebar' style='font-family:微软雅黑;font-size:16px;color:#0B903C;font-weight:bold;line-height:50px;'>刑侦案件来源分布</p>
  <div class="main"></div>
</div>

</template>

<script>
import echarts from 'echarts'
import header from 'components/header/header'
import filter from 'components/filter/filter'
import axios from 'axios'
import bus from 'src/bus'
export default {
  data() {
    return {
      legendArr: [],
      color: this.$store.state.color,
      styleArr: [],
      myChart: {},
      name: ''
    }
  },
  methods: {
    _init() {
      this.legendArr = this.myChart.getOption().series
      this.legendArr.forEach((data) => {
        data.selected = true;
      })
      this.$root.charts.push(this.myChart)
      window.addEventListener('resize', function() {
        this.myChart.resize()
      }.bind(this))
    }
  },
  components: {
    'v-header': header,
    'v-filter': filter
  },
  mounted() {
    // 基于准备好的dom，初始化echarts实例
    this.myChart = echarts.init(document.querySelector('.xingzhenmultiplebar .main'))
    this.myChart.on("click", function(params) {
      // localStorage.setItem('areaname', params.name)
      // location.href = "/vue/#/anzhibangs?areaname=" + params.name;
    })
    axios.get(this.GLOBAL.BASE_URL + '/a/sys/area/xingzhenData?name=平顶山市').then((res) => {
    // axios.get('static/data/Data1.json').then((res) => {
      if (res) {
        var arrname = [];
        var seriesarr = [];
        var xingzhenufname = [];
        var arrs = [];
        var xingzhenuf = res.data[0]['xingzhenuf'].split(",");
        xingzhenuf.pop();
        $(xingzhenuf).each(function(index, item) {
          xingzhenufname[xingzhenufname.length] = item;
          arrs = [];
          $(res.data).each(function() {
            if (this.name !== "平顶山市") {
              arrname[arrname.length] = this.name;
              var arr2 = this.xingzhenufromcount.split(",");
              arr2.pop();
              arrs[arrs.length] = arr2[index];
            }
          })
          seriesarr[seriesarr.length] = {
            name: item,
            type: 'bar',
            stack: '总量',
            label: {
              normal: {
                show: true,
                position: 'insideLeft'
              }
            },
            data: arrs
          }
        })
        localStorage.setItem('areadata', JSON.stringify(res.data));
        this.myChart.setOption({
          tooltip: {
            trigger: 'axis',
            axisPointer: {
              type: 'shadow'
            }
          },
          legend: {
            data: xingzhenufname
          },
          grid: {
            left: '3%',
            right: '4%',
            bottom: '3%',
            containLabel: true
          },
          xAxis: {
            axisLine: {
              show: true,
              lineStyle: {
                color: '#00AA5E'
              }
            },
            type: 'value',
            splitLine: {
              show: false
            }
          },
          yAxis: {
            type: 'category',
            data: arrname,
            axisLine: {
              show: true,
              lineStyle: {
                color: '#00AA5E'
              }
            },
            splitLine: {
              show: false
            }
          },
          series: seriesarr
        });
        this._init()
      }
    });
  }
}

</script>
